<?php

namespace Luka\NavigationBundle\Templating\Helper;

use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\Templating\EngineInterface;
use Luka\NavigationBundle\Model\Items;

class MenuHelper extends Helper
{
    protected $templating;
    protected $menu;

    public function __construct(EngineInterface $templating, Items $menu)
    {
        $this->templating  = $templating;
        $this->menu = $menu;
    }

    /**
     * Returns the HTML for the menu
     *
     * @param $name
     * @return string A HTML string
     */
    public function menu(array $options = array())
    {
        return $this->templating->render(
                "LukaNavigationBundle::menu.html.twig",
                $this->resolveOptions($options)
        );
    }

    /**
     * @codeCoverageIgnore
     */
    public function getName()
    {
        return 'luka_navigation_menu_helper';
    }

    private function resolveOptions(array $options = array())
    {
        return array_merge(
                array(
                        'menu' => $this->menu,
                        'translation_domain' => null,
                        'locale' => null,
                        'listId' => 'ln-menu',
                        'listClass' => 'menu',
                        'separator' => '/'
                ), $options
        );
    }
}
